library(ggplot2)

# Change in MSE with sample size
samples = c(10, 20, 30, 50, 75, 100, 150, 200, 500, 1000)
MSE_bonobo = c(0.0987,0.0478,0.0351,0.0234,0.0176,0.0152,0.0127,0.0112, 0.0091,0.0083)
MSE_bonobo_sparse = c(0.0592,0.0474,0.0451,0.0448,0.0447,0.0449,0.0446,0.0448, 0.0447, 0.0447)
MSE_lioness = c(0.1660,0.1608,0.1582,0.1570,0.1558,0.1559,0.1550,0.1551, 0.1546,0.1545)
MSE_spcc = c(0.1732,0.1735,0.1732,0.1733,0.1732,0.1739,0.1734,0.1731,0.1732,0.1734)
MSE_sweet = c(0.0923,0.0489,0.0378,0.0272,0.0217,0.0195,0.0173,0.0160,0.0142,0.0137)

fulldata = data.frame(c(MSE_bonobo, MSE_lioness, MSE_spcc, MSE_sweet))
colnames(fulldata) = "MSE"
fulldata$sample_size = c(samples, samples, samples, samples)
fulldata$Method = c(rep("BONOBO", length(MSE_bonobo)), rep("LIONESS", length(MSE_lioness)), rep("SPCC", length(MSE_spcc)), rep("SWEET", length(MSE_sweet)))

ggplot(fulldata, aes(x=sample_size, y=MSE, group=Method, color=Method)) +
  geom_line(size=1) + ggtitle("Change in MSE with sample size") + xlab("sample size") +
  theme(legend.position = c(0.8,0.6), axis.title = element_text(size = 15), title = element_text(size = 15))

newdata = data.frame(samples)
newdata$percentage = 100*(MSE_sweet-MSE_bonobo)/MSE_sweet

ggplot(newdata, aes(x=samples, y=percentage)) +
  geom_line(size=1) + ggtitle("Decrease in MSE of BONOBO wrt MSE of SWEET") + xlab("sample size") + ylab("% decrease in MSE") +
  theme(legend.position = c(0.8,0.6), axis.title = element_text(size = 15), title = element_text(size = 15))

#########################################

# Change in MSE with Proportion of altered samples
mix_prop = c(5, 10, 20, 30, 40, 50, 75, 90, 95)
MSE_bonobo = c(0.0332,0.0276,0.0253,0.0273,0.0239,0.0249,0.0138,0.0132,0.0098)
MSE_bonobo_sparse = c(0.0038,0.0007,0,0,0,0,0,0,0)
MSE_lioness = c(0.1784,0.1690,0.1530,0.1074,0.0695,0.0473,0.0159,0.0058,0.0028)
MSE_spcc = c(0.0561,0.1079,0.1228,0.0806,0.0509,0.0343,0.0115,0.0039,0.0018)
MSE_sweet = c(0.0179,0.0181,0.0182,0.0187,0.0187,0.0191,0.0197,0.0199,0.0197)
MSE_sparse_sweet = c(0,0,0,0,0,0,0,0,0)

fulldata = data.frame(c(MSE_bonobo, MSE_bonobo_sparse, MSE_lioness, MSE_spcc, MSE_sweet, MSE_sparse_sweet))
colnames(fulldata) = "MSE"
fulldata$mix_prop = c(mix_prop, mix_prop, mix_prop, mix_prop, mix_prop, mix_prop)
fulldata$Method = c(rep("BONOBO", length(MSE_bonobo)), rep("sparse BONOBO", length(MSE_bonobo_sparse)), rep("LIONESS", length(MSE_lioness)), rep("SPCC", length(MSE_spcc)), rep("SWEET", length(MSE_sweet)), rep("sparse SWEET", length(MSE_sparse_sweet)))
fulldata$Method = factor(fulldata$Method, levels = c("BONOBO", "sparse BONOBO", "LIONESS", "SPCC", "SWEET", "sparse SWEET"))

library(ggplot2)
ggplot(fulldata, aes(x=mix_prop, y=MSE, group=Method, color=Method)) +
  geom_line(size = 1) + ggtitle("Change in MSE with Proportion of Altered Samples") + xlab("% of samples altered") +
  scale_color_manual(values=c("red", "blue", "green3", "cyan3", "violet", "pink")) +
  theme(legend.position = c(0.8,0.6), axis.title = element_text(size = 15), title = element_text(size = 15))

#################################################
# Change in MSE with number of genes (homogeneous data)
genes = c(100, 250, 500, 750, 1000, 1500)
vars = c(0.1667,0.1456,0.1024,0.0775,0.0692,0.0593)
MSE_bonobo = c(0.0152,0.0166,0.0168,0.0175,0.0176,0.0178)/vars
MSE_lioness = c(0.1559,0.1439,0.1077,0.0881,0.0810,0.0738)/vars
MSE_spcc = c(0.1739,0.1550,0.1126,0.0910,0.0833,0.0756)/vars
MSE_sweet = c(0.0195,0.0210,0.0222,0.0234,0.0238,0.0242)/vars

fulldata = data.frame(c(MSE_bonobo, MSE_lioness, MSE_spcc, MSE_sweet))
colnames(fulldata) = "MSE"
fulldata$genes = c(genes, genes, genes, genes)
fulldata$Method = c(rep("BONOBO", length(MSE_bonobo)), rep("LIONESS", length(MSE_lioness)), rep("SPCC", length(MSE_spcc)), rep("SWEET", length(MSE_sweet)))

ggplot(fulldata, aes(x=genes, y=MSE, group=Method, color=Method)) + 
  geom_line(size=1) + ggtitle("Change in MSE with number of genes\n(homogeneous data)") + xlab("number of genes") + ylab("scaled MSE") +
  theme(legend.position = c(0.8,0.6), axis.title = element_text(size = 15), title = element_text(size = 15))

r2 = c(1-MSE_bonobo, 1-MSE_sweet)
newdata = data.frame(c(genes, genes))
colnames(newdata) = "genes"
newdata$r2 = r2
newdata$Method = c(rep("BONOBO", length(MSE_bonobo)), rep("SWEET", length(MSE_sweet)))
  
ggplot(newdata, aes(x=genes, y=r2, color = Method)) + scale_color_manual(values=c("red", "violet")) +
  geom_line(size=1) + ggtitle("Change in R_squared with number of genes") + xlab("number of genes") + ylab("R_squared") +
  theme(legend.position = c(0.8,0.7), axis.title = element_text(size = 15), title = element_text(size = 15))
  
newdata = data.frame(genes)
newdata$percentage = 100*(MSE_sweet-MSE_bonobo)/MSE_sweet

ggplot(newdata, aes(x=genes, y=percentage)) +
  geom_line(size=1) + ggtitle("Decrease in MSE of BONOBO wrt MSE of SWEET") + xlab("sample size") + ylab("% decrease in MSE") +
  theme(legend.position = c(0.8,0.6), axis.title = element_text(size = 15), title = element_text(size = 15))

#################################################
# Change in MSE with number of genes (heterogeneous data)
genes = c(100, 250, 500, 750, 1000, 1500)
vars = c(0.1674,0.1464,0.1016,0.0787,0.0685,0.0600)
MSE_bonobo = c(0.0339,0.0349,0.0353,0.0334,0.0493,0.0479)/vars
MSE_lioness = c(0.1495,0.1391,0.1050,0.0871,0.0774,0.0712)/vars
MSE_spcc = c(0.1737,0.1546,0.1122,0.0915,0.0821,0.0749)/vars
MSE_sweet = c(0.0370,0.0383,0.0397,0.0383,0.0540,0.0529)/vars

fulldata = data.frame(c(MSE_bonobo, MSE_lioness, MSE_spcc, MSE_sweet))
colnames(fulldata) = "MSE"
fulldata$genes = c(genes, genes, genes, genes)
fulldata$Method = c(rep("BONOBO", length(MSE_bonobo)), rep("LIONESS", length(MSE_lioness)), rep("SPCC", length(MSE_spcc)), rep("SWEET", length(MSE_sweet)))

ggplot(fulldata, aes(x=genes, y=MSE, group=Method, color=Method)) + 
  geom_line(size=1) + ggtitle("Change in MSE with number of genes\n(mixture data)") + xlab("number of genes") + ylab("scaled MSE") +
  theme(legend.position = c(0.8,0.25), axis.title = element_text(size = 15), title = element_text(size = 15))

newdata = data.frame(genes)
newdata$percentage = 100*(MSE_sweet-MSE_bonobo)/MSE_sweet

ggplot(newdata, aes(x=genes, y=percentage)) +
  geom_line(size=1) + ggtitle("Decrease in MSE of BONOBO wrt MSE of SWEET") + xlab("sample size") + ylab("% decrease in MSE") +
  theme(legend.position = c(0.8,0.6), axis.title = element_text(size = 15), title = element_text(size = 15))

#######################################
# Change in MSE with Mixture Proportion
mix_prop = c(0, 10, 20, 30, 40, 50)
MSE_bonobo = c(0.0152,0.0592,0.0339,0.0392,0.0423,0.0547)
MSE_bonobo_sparse = c(0.0449,0.0477,0.0490,0.0509,0.0492,0.0489)
MSE_lioness = c(0.1559,0.1384,0.1495,0.1551,0.1608,0.1498)
MSE_spcc = c(0.1739,0.1748,0.1737,0.1728,0.1757,0.1693)
MSE_sweet = c(0.0195,0.0607,0.0370,0.0427,0.0464,0.0581)

fulldata = data.frame(c(MSE_bonobo, MSE_lioness, MSE_spcc, MSE_sweet))
colnames(fulldata) = "MSE"
fulldata$mix_prop = c(mix_prop, mix_prop, mix_prop, mix_prop)
fulldata$Method = c(rep("BONOBO", length(MSE_bonobo)), rep("LIONESS", length(MSE_lioness)), rep("SPCC", length(MSE_spcc)), rep("SWEET", length(MSE_sweet)))

library(ggplot2)
ggplot(fulldata, aes(x=mix_prop, y=MSE, group=Method, color=Method)) +
  geom_line(size=1) + ggtitle("Change in MSE with Mixture Proportion") + xlab("% of samples in smaller group") +
  theme(legend.position = c(0.8,0.6), axis.title = element_text(size = 15), title = element_text(size = 15))

newdata = data.frame(mix_prop)
newdata$percentage = 100*(MSE_sweet-MSE_bonobo)/MSE_sweet

ggplot(newdata, aes(x=mix_prop, y=percentage)) +
  geom_line(size=1) + ggtitle("Decrease in MSE of BONOBO wrt MSE of SWEET") + xlab("% of samples in smaller group") + ylab("% decrease in MSE") +
  theme(legend.position = c(0.8,0.6), axis.title = element_text(size = 15), title = element_text(size = 15))
